<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>对数组元素进行排序</title>
</head>
<body>
<script>
    var myShopping = ['Eggs', 'Milk', 'Potatoes', 'Cereal', 'Banana'];
    var ord = prompt('Enter 1 for alphabetical order, and -1 for reverse order', '1');

    if (ord == 1) {
        myShopping.sort();
        document.write(myShopping.join('<br/>'));
    } else if (ord == -1) {
        myShopping.sort();
        myShopping.reverse();
        document.write(myShopping.join('<br/>'));
    } else {
        document.write('Than is not a valid input');
    }
</script>
</body>
</html>